package com.wn32.main.demo15;

import com.huaban.analysis.jieba.JiebaSegmenter;
import com.huaban.analysis.jieba.SegToken;
import redis.clients.jedis.Jedis;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        String sql = "select * from poetry";
        List<Poetry> list = DbUtils.query(sql, Poetry.class);
        for (Poetry p : list) {
            String str = p.getTitle() + "-" + p.getContent();
            JiebaSegmenter seg = new JiebaSegmenter();
            List<SegToken> tokens = seg.process(p.getContent(), JiebaSegmenter.SegMode.INDEX);
            for (SegToken token : tokens) {
                if (token.word.length() > 1) {
                    jedis.sadd(token.word, p.getId() + "");
                }
            }
            System.out.println("加工完成:" + p.getTitle());
        }
    }
}
